package demo3;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {

    public static List<Character> func(String s1, String s2) {

        List<Character> list = new ArrayList<>();
        for (int i = 0; i < s1.length(); i++) {
            char ch1 = s1.charAt(i);

            boolean flg = false;
            for (int j = 0; j < s2.length(); j++) {
                char ch2 = s2.charAt(j);
                if (ch1 == ch2) {
                    flg = true;
                    break;
                }
            }

            if (flg == false) {
                list.add(ch1);
            }
        }
        return list;
    }

    public static List<Character> func2(String s1, String s2) {

        List<Character> list = new ArrayList<>();
        for (int i = 0; i < s1.length(); i++) {
            char ch = s1.charAt(i);

//            boolean flg = false;
//            for (int j = 0; j < s2.length(); j++) {
//                char ch2 = s2.charAt(j);
//                if (ch1 == ch2) {
//                    flg = true;
//                    break;
//                }
//            }
//
//            if (flg == false) {
//                list.add(ch1);
//            }

            if (!s2.contains(ch+"")) {
                list.add(ch);
            }
        }
        return list;
    }


    public static void main5(String[] args) {
        List<Character> list = func("welcome to oyie", "come");
        //System.out.println(list);
        for (char ch : list) {
            System.out.print(ch);
        }
    }

    // 杨辉三角
    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();

        List<Integer> one = new ArrayList<>();
        one.add(1);
        ret.add(one);
        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            for (int j = 1; j < i; j++) {
                List<Integer> preRow = ret.get(i-1);
                int x = preRow.get(j-1) + preRow.get(j);
                curRow.add(x);
            }
            curRow.add(1);
            ret.add(curRow);
        }
        return ret;
    }

    public static void main4(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(5);
        System.out.println(arrayList);

        // for循环+下标
        System.out.println("========for循环+下标=======");
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i) + " ");
        }
        System.out.println();

        // for-each
        System.out.println("========for-each=======");
        for (Integer x : arrayList) {
            System.out.print(x + " ");
        }
        System.out.println();

        // 使用迭代器
        System.out.println("========Iterator迭代器=======");
        Iterator<Integer> it = arrayList.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();

        // 使用迭代器
        System.out.println("========listIterator()迭代器=======");
        Iterator<Integer> it2 = arrayList.listIterator();
        while (it2.hasNext()) {
            System.out.print(it2.next() + " ");
        }
        System.out.println();
    }

    public static void main3(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(5);
        arrayList.add(6);
        arrayList.add(7);
        arrayList.add(8);
        arrayList.add(9);
        System.out.println(arrayList);
        arrayList.set(0,100);
        System.out.println(arrayList);
    }

    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(99);
        arrayList.add(3);
        arrayList.add(4);
        System.out.println("arrayList:" + arrayList);

        List<Integer> list = arrayList.subList(1,3); // [1, 3)
        System.out.println("list:" + list);

        System.out.println("============================");
        list.set(0,100);

        System.out.println("list.set(0,100):" + list);
        System.out.println("此时arrayList" + arrayList);
    }

    public static void main1(String[] args) {
        // ArrayList无参构造，构造一个空的列表
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);
        arrayList1.add(2);
        arrayList1.add(3);
        arrayList1.add(99);
        System.out.println(arrayList1);

        // arrayList2构造好之后，与arrayList1中的元素一致
        ArrayList<Integer> arrayList2 = new ArrayList<>(arrayList1);
        System.out.println(arrayList2);

        // 构造一个具有10个容量的列表
        ArrayList<Integer> arrayList3 = new ArrayList<>(10);


        arrayList1.remove(0);
        arrayList1.remove(new Integer(99));

        ArrayList<String> arrayList4 = new ArrayList<>();
        arrayList4.add("ss");
        ArrayList<String> arrayList5 = new ArrayList<>();
        arrayList5.addAll(arrayList4);
        System.out.println(arrayList4);
        System.out.println(arrayList5);
    }

public static void main0(String[] args) {
    ArrayList<String> arrayList = new ArrayList<>();
    arrayList.add("hello");
    arrayList.add("world");
    arrayList.add("this");
    arrayList.add("is");
    arrayList.add("frost");

    System.out.println(arrayList.contains(new String("hello")));
    System.out.println(arrayList.contains(new Integer(99)));
    System.out.println(arrayList.contains("rost"));
}
}
